﻿/*
Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
if(!CKEDITOR._08cms)CKEDITOR._08cms = {};
if(!CKEDITOR._08cms.stack)CKEDITOR._08cms.stack = [];
!function(){
var key, lang, langs = {
		en		: {
			image		: 'PicUpload',
			modeError	: 'You must be in WYSIWYG mode!'
		},
		zh		: {
			image		: '圖片上傳',
			modeError	: '請退出源碼編輯模式再使用本功能！'
		},
		'zh-cn'	: {
			image		: '图片上传',
			modeError	: '请退出源码编辑模式再使用本功能！'
		}
	};
for(var key in CKEDITOR.lang){if(key in CKEDITOR.lang.languages){
	lang = key;
	(key in langs) || (key = 'en');
	CKEDITOR.lang[lang] || (CKEDITOR.lang[lang] = CKEDITOR.lang.en);
	CKEDITOR.lang[key].fileupload = langs[key];
	CKEDITOR.lang[key].fakeobjects.fileupload = langs[key].fakeobjects;
	break;
}}
CKEDITOR.plugins.add( '08cms_bottom',{
	init : function( editor ){
		editor.on( 'themeSpace', function( event ){
			if ( event.data.space == 'bottom' ){
				var id = CKEDITOR._08cms.stack.push(editor) - 1;
				event.data.html += '<div class="cke_footer">'
					+ (editor.config.fileupload && editor.config.fileupload.image ?
						'<a href="javascript:void(0)" onclick="CKEDITOR._08cms.fileupload.images(' + id + ');return false">'
						+ editor.lang.fileupload.image + '</a>' : '')
					+'</div>'
			}
		});
	},

	requires : [ 'fakeobjects' ]
} );
}();

CKEDITOR._08cms.fileupload = {
	images		: function(id){
		var editor = CKEDITOR._08cms.stack[id]
			, config = editor.config.fileupload.image;
		if(editor.mode != 'wysiwyg'){
			alert(editor.lang.fileupload.modeError);
		}else{
			uploadwin('images', function(images){
				var a, i = 0, l = images.length, html = '';
				while(i < l){
					a = images[i++].split('|');
					a[0] && (html += '<img alt="' + (a[1] || '') + '" src="' + a[0] + '"/>');
				}
				editor.insertHtml(html);
			}, config.mincount, config.maxcount, 0, config.watermark);
		}
	}
};